package com.shuoyue.ycgk.ui.recruitment.his;

import android.content.Intent;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.baseadapter.AppBaseQuickAdapter;
import com.shuoyue.ycgk.entity.JobHis;
import com.shuoyue.ycgk.entity.JobInfo;
import com.shuoyue.ycgk.entity.RecruitmentItem;
import com.shuoyue.ycgk.entity.RecruitmentItemHis;
import com.shuoyue.ycgk.ui.recruitment.job.JobAdapter;
import com.shuoyue.ycgk.ui.recruitment.job.JobDetailActivity;
import com.shuoyue.ycgk.ui.recruitment.newsinfo.NoticeAdapter;
import com.shuoyue.ycgk.ui.recruitment.newsinfo.RecurimentInfoActivity;
import com.shuoyue.ycgk.utils.SizeUtil;
import com.shuoyue.ycgk.utils.SpacesItemDecoration;

import java.util.List;

public class HisNewsAdapter extends AppBaseQuickAdapter<RecruitmentItemHis> {
    public HisNewsAdapter(@Nullable List<RecruitmentItemHis> data) {
        super(R.layout.item_his, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, RecruitmentItemHis item) {
        helper.setText(R.id.date, item.getDate());

        RecyclerView recyclerView = helper.getView(R.id.childRecycleView);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        if (recyclerView.getTag() == null) {
            recyclerView.addItemDecoration(new SpacesItemDecoration(SizeUtil.dip2px(mContext, 1), false));
            recyclerView.setTag("tag");
        }
        NoticeAdapter childAdapter = new NoticeAdapter(item.getExaminationNoticeListDTOS(),true);
        recyclerView.setAdapter(childAdapter);
        childAdapter.setOnItemChildClickListener((adapter, view, position) -> {
            RecruitmentItem c = (RecruitmentItem) adapter.getItem(position);
            switch (view.getId()) {
                case R.id.delete:
                    if (deleteCall != null) {
                        deleteCall.delete(childAdapter, c);
                    }
                    break;
                case R.id.lay_all:
                    mContext.startActivity(new Intent(mContext, RecurimentInfoActivity.class)
                            .putExtra("id", c.getId()));
                    break;
            }

        });
    }

    public void setDeleteCall(DeleteCall deleteCall) {
        this.deleteCall = deleteCall;
    }

    DeleteCall deleteCall;

    public interface DeleteCall {
        void delete(AppBaseQuickAdapter adapter, RecruitmentItem info);
    }
}
